#define _CRT_SECURE_NO_WARNINGS

class Solution {
public:
    bool lemonadeChange(vector<int>& bills) {
        if (bills[0] != 5)
            return false;
        unordered_map<int, int> um;
        for (int i = 0; i < bills.size(); i++)
        {
            if (bills[i] == 5)
                um[bills[i]]++;
            else if (bills[i] == 10)
            {
                if (um.find(5) != um.end() && (um.find(5)->second)-- == 0)
                    return false;
                um[bills[i]]++;
            }
            else
            {
                if (um.find(10) != um.end() && (um.find(10)->second) > 0 && um.find(5) != um.end() && (um.find(5)->second) > 0)
                {
                    um[5]--;
                    um[10]--;
                }
                else if ((um.find(5)->second) > 2)
                    um[5] = um[5] - 3;
                else
                    return false;
                um[bills[i]]++;
            }
        }
        return true;
    }
};

class Solution {
public:
    bool lemonadeChange(vector<int>& bills) {
        if (bills[0] != 5)
            return false;
        int bills_num_5 = 0;
        int bills_num_10 = 0;
        for (int i = 0; i < bills.size(); i++)
        {
            if (bills[i] == 5)
                bills_num_5++;
            else if (bills[i] == 10)
            {
                if (bills_num_5 == 0)
                    return false;
                bills_num_5--;
                bills_num_10++;
            }
            else
            {
                if (bills_num_10 > 0 && bills_num_5 > 0)
                {
                    bills_num_5--;
                    bills_num_10--;
                }
                else if (bills_num_5 > 2)
                    bills_num_5 = bills_num_5 - 3;
                else
                    return false;
            }
        }
        return true;
    }
};

class Solution {
public:
    static bool cmp(vector<int> a, vector<int> b)
    {
        if (a[0] == b[0])
            return a[1] < b[1];
        return a[0] > b[0];
    }

    vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {
        vector<vector<int>> ret;
        sort(people.begin(), people.end(), cmp);
        for (int i = 0; i < people.size(); i++)
        {
            int position = people[i][1];
            ret.insert(ret.begin() + position, people[i]);
        }
        return ret;
    }
};

class Solution {
public:
    int findMinArrowShots(vector<vector<int>>& points) {
        vector<vector<int>> ret;
        sort(points.begin(), points.end());
        for (int i = 0; i < points.size(); i++)
        {
            if (i == 0)
                ret.push_back(points[i]);
            else
            {
                cout << "*";
                if (ret[ret.size() - 1][1] >= points[i][0])
                {
                    int tmp = (ret[ret.size() - 1][1] > points[i][1]) ? points[i][1] : ret[ret.size() - 1][1];
                    ret.pop_back();
                    ret.push_back({ points[i][0],tmp });
                }
                else
                    ret.push_back(points[i]);
            }
        }
        return ret.size();
    }
};

class Solution {
public:
    int findMinArrowShots(vector<vector<int>>& points) {
        sort(points.begin(), points.end());
        int right = right = points[0][1];;
        int ret = 1;
        for (int i = 0; i < points.size(); i++)
        {
            if (points[i][0] > right)
            {
                ret++;
                right = points[i][1];
            }
            else
            {
                if (points[i][1] < right)
                    right = points[i][1];
            }
        }
        return ret;
    }
};